#pragma once
#ifndef IO_BINARYREADER_H
#define IO_BINARYREADER_H
//------------------------------------------------------------------------------
/**
    @class Core::BinaryReader
    
    A friendly interface to read binary data from a stream. Optionally the
    reader can use memory mapping for optimal read performance. Performs
    automatic byte order conversion if necessary.

    @todo convert endianess!
    
    (C) 2006 Radon Labs GmbH
*/
#include "streamreader.h"
//------------------------------------------------------------------------------
namespace GBase
{
	class BinaryReader : public StreamReader
	{
	public:
		/// constructor
		BinaryReader();
		/// destructor
		virtual ~BinaryReader();
		/// call before Open() to enable memory mapping (if stream supports mapping)
		void SetMemoryMappingEnabled(bool b);
		/// return true if memory mapping is enabled
		bool IsMemoryMappingEnabled() const;
		/// begin reading from the stream
		virtual bool Open();
		/// end reading from the stream
		virtual void Close();
		/// read an 8-bit char from the stream
		char ReadChar();
		/// read an 8-bit unsigned character from the stream
		unsigned char ReadUChar();
		/// read a 16-bit short from the stream
		short ReadShort();
		/// read a 16-bit unsigned short from the stream
		unsigned short ReadUShort();
		/// read a 32-bit int from the stream
		int ReadInt();
		/// read a 32-bit unsigned int from the stream
		unsigned int ReadUInt();
		/// read a float value from the stream
		float ReadFloat();
		/// read a double value from the stream
		double ReadDouble();
		/// read a bool value from the stream
		bool ReadBool();
		/// read a 64-bit int from the stream
		long long ReadLLong();
		/// read a 64-bit unsigned int from the stream
		unsigned long long ReadULLong();

		char* ReadString1024();
		void ReadRawData(void* ptr, unsigned int numBytes);

	public:
		bool enableMapping;
		bool isMapped;
		//System::ByteOrder byteOrder;
		unsigned char* mapCursor;
		unsigned char* mapEnd;
	};

	//------------------------------------------------------------------------------
	/**
	*/
	inline void
	BinaryReader::SetMemoryMappingEnabled(bool b)
	{
		this->enableMapping = b;
	}

	//------------------------------------------------------------------------------
	/**
	*/
	inline bool
	BinaryReader::IsMemoryMappingEnabled() const
	{
		return this->enableMapping;
	}

	//------------------------------------------------------------------------------
	/**
	*/
	//inline void
	//BinaryReader::SetStreamByteOrder(System::ByteOrder::Type order)
	//{
	//	this->byteOrder.SetFromByteOrder(order);
	//}

	////------------------------------------------------------------------------------
	///**
	//*/
	//inline System::ByteOrder::Type
	//BinaryReader::GetStreamByteOrder() const
	//{
	//	return this->byteOrder.GetFromByteOrder();
	//}

} // namespace Core
//------------------------------------------------------------------------------
#endif